<!-- 页面 -->
<template>
	<s-layout navbar="normal" class="p-3">
		<view class="d-flex align-items-stretch channel-title-box bg-white">
<!--			<h4 class="channel-title">资料下载</h4>-->
		</view>
		<s-tiku-category @update:selected="handleCategoryChange" content_type="ziliao" :isTk="false" />
		
		<s-empty v-if="state.list.length === 0" icon="/static/order-empty.png" text="暂无资料"></s-empty>
		<view v-if="state.list.length > 0">
			<view class="bg-white order-list-card-box ss-r-10 ss-m-t-14 ss-m-20" v-for="item in state.list"
				:key="item.id">
				<view class="ss-order-card-warp ss-flex ss-col-stretch">
					<view class="img-box">
						<uni-icons custom-prefix="iconfont" type="icon-wenjian" size="18"
							style="color:#f8cd88;"></uni-icons>
					</view>
					<view class="box-right ss-flex-col ss-row-between">
						<view class="title-text ss-line-2">{{ item.title }}</view>
					</view>
					
					<view class="rightbuttons" style="cursor: pointer;">
						<view  v-if="item.is_download==1" @click="downloadZiliao(item.document_url,item.title)">
							<uni-icons type="download" size="16" color="var(--ui-BG-Main)"></uni-icons> 下载资料
						</view>
						<view v-else  @tap="navigatorToZiliao(item.id)">
							<uni-icons type="eye" size="18" color="var(--ui-BG-Main)"></uni-icons> 查看资料
						</view>
					</view>
				</view>
			</view>
		</view>
	</s-layout>
</template>

<script setup>
	import {
		computed,
		reactive
	} from 'vue';
	import {
		onLoad,
		onReachBottom,
		onPullDownRefresh
	} from '@dcloudio/uni-app';
	import {
		formatOrderColor
	} from '@/sheep/hooks/useGoods';
	import sheep from '@/sheep';
	import _ from 'lodash';
	import {
		isEmpty
	} from 'lodash';
	import {
		downloadFile
	} from '@/sheep/helper/download.js';

	const tradeManaged = computed(() => sheep.$store('app').has_wechat_trade_managed);


	// 数据
	const state = reactive({
		list: [],
		loadStatus: '',
		error: 0,
		category1: undefined,
		category2: undefined,
		year: undefined,
	});

	// 获取订单列表
	async function listCourseByUser() {
		state.loadStatus = 'loading';
		let res = await sheep.$api.course.listCourseByUser({
			content_type: 'ziliao',
			category1: state.category1,
			category2: state.category2,
			year: state.year,
		});
		state.error = res.error;
		if (res.code === 1) {
			console.log(res)
			state.list = res.data;
		}
	}

	onLoad(async (options) => {
		listCourseByUser();
	});
	
	const handleCategoryChange = (selection) => {
		state.category1 = selection.category1;
		state.category2 = selection.category2;
		state.year = selection.year;
		listCourseByUser();
	}
	
	function navigatorToZiliao(id) {
		//type：goods表示商品，lesson表示课件
		sheep.$router.navigatorToZiliao(id, 'goods');
	}
	
	function downloadZiliao(download_url, title) {
		console.log(download_url)
		downloadFile(download_url, title);
	}
</script>

<style lang="scss" scoped>
	@import "@/static/iconfont/iconfont.css";

	::v-deep .page-body{background-color:#FFFFFF !important;}
	.channel-title-box {
		display: flex;
		align-items: flex-start;
	}

	.channel-title {
		font-size: 20px;
		font-weight: bold;
		margin-bottom: 50px;
		flex: 1 1 auto !important;
	}

	.ss-row-right {
		justify-content: flex-start;
	}

	.coursebottom {
		display: flex;
		justify-content: space-between;
		border-top: 1px solid #e1e1e1;
		height: 50px;
		align-items: center;
		margin: 0 6px;

		.left {
			width: 70%
		}

		.right {
			width: 30%;
			display: flex;
			justify-content: center;
			/* 水平居中 */
			align-items: center;
			/* 垂直居中 */
		}

		.courseinfo {
			font-size: 12px;
			color: #666666;
		}

		.confirm-btn {
			width: 130rpx;
			height: 40rpx;
			background: linear-gradient(90deg, #ff6000, #fe832a);
			box-shadow: 0 0.2em 0.5em rgba(#ff6000, 0.4);
			border-radius: 0rpx;
			font-size: 28rpx;
			font-weight: 500;
			color: #ffffff;
			line-height: normal;
		}
	}


	.ss-order-card-warp {
		padding: 20rpx;
		align-items: center;
		
		&:hover {
			background-color: #f6f6f6 !important;
			cursor: pointer;
		}

		.img-box {
			width: 54rpx;
			height: auto;
			overflow: hidden;
			padding-top: 3px;

			.order-img {
				max-width: 100%;
				height: auto;
				border-radius: 6rpx;
			}
		}

		.box-right {
			flex: 1;
			position: relative;
		}

		.title-text {
			font-size: 32rpx;
			font-weight: 500;
			line-height: 40rpx;
		}
	}

	.info-color {
		color: var(--ui-BG-Main);
	}

	.rightbuttons {
		width: 200rpx;
		color: var(--ui-BG-Main);
		font-size: 30rpx;
	}
	.order-list-card-box{
		cursor: pointer;
		
		&:hover {
			background-color: #f6f6f6;
			cursor: pointer;
		}
	}
</style>